import { VibrateShort } from "@/utils";
import Taro from "@tarojs/taro";
import { makeAutoObservable } from "mobx";

class Store {
    isNight = Taro.getStorageSync('is-night') === true
    // 没缓存时自动跟随
    isFllow = Taro.getStorageSync('is-fllow') !== false
    isBehind = false
    // 当账号需要指纹验证时需要确认是否正在等待通过验证
    isIdentityCheckWait = false
    // 分类选择器是否打开
    categoryVisible = false
    // 系统振动是否开启
    shakeAvailable = Taro.getStorageSync('sys-shake-available') !== false
    // 记账方式（默认表单方式）
    recordType: 'form' | 'chat' = Taro.getStorageSync('sys-record-type') || 'form'
    // 全局字体大小
    fontSize = Taro.getStorageSync('sys-font-size') || 'mini'
    // page组件刷新页面使用
    key = 0
    setNight(val: boolean) {
        this.isNight = val
        Taro.setStorageSync('is-night', val)
    }
    setFllow(val: boolean) {
        this.isFllow = val
        Taro.setStorageSync('is-fllow', val)
    }
    setBehind(val: boolean, quiet?: boolean) {
      if (!quiet) {
        VibrateShort()
      }
      this.isBehind = val
    }
    setIsIdentityCheckWait(val: boolean) {
        this.isIdentityCheckWait = val
    }
    setCategoryVisible(val:boolean) {
      this.categoryVisible = val
    }
    setshakeAvailable(val:boolean) {
      Taro.setStorageSync('sys-shake-available', val)
      this.shakeAvailable = val
    }
    记账方式切换
    setRecordType(val: 'form' | 'chat') {
      Taro.setStorageSync('sys-record-type', val)
      this.recordType = val
    }
    setfontSize(val:string) {
      Taro.setStorageSync('sys-font-size', val)
      this.fontSize = val
    }
    refresh() {
      this.key = new Date().getTime()
    }
    constructor() {
      makeAutoObservable(this);
    }
  }
  
  export default new Store();